
#if !defined(__ShellCode__)
#include "ShellCode.h"
#define __ShellCode__
#endif

BOOL InitShellFunc_R0(PShellFunc_R0 m) {
	//**//
	m->PsCreateSystemThread = (PVOID)GetProcAddress(L"PsCreateSystemThread");
	if (m->PsCreateSystemThread == 0) {
		goto Exit;
	}
	m->PsLookupProcessByProcessId = (PVOID)GetProcAddress(L"PsLookupProcessByProcessId");
	if (m->PsLookupProcessByProcessId == 0) {
		goto Exit;
	}
	m->strcmp = (PVOID)GetProcAddress(L"strcmp");
	if (m->strcmp == 0) {
		goto Exit;
	}
	m->memcpy = (PVOID)GetProcAddress(L"memcpy");
	if (m->memcpy == 0) {
		goto Exit;
	}
	m->memset = (PVOID)GetProcAddress(L"memset");
	if (m->memset == 0) {
		goto Exit;
	}
	m->PsGetProcessImageFileName = (PVOID)GetProcAddress(L"PsGetProcessImageFileName");
	if (m->PsGetProcessImageFileName == 0) {
		goto Exit;
	}
	m->ObDeObject = (PVOID)GetProcAddress(L"ObfDereferenceObject");
	if (m->ObDeObject == 0) {
		goto Exit;
	}
	m->KeStackAttachProcess = (PVOID)GetProcAddress(L"KeStackAttachProcess");
	if (m->KeStackAttachProcess == 0) {
		goto Exit;
	}
	m->KeUnstackDetachProcess = (PVOID)GetProcAddress(L"KeUnstackDetachProcess");
	if (m->KeUnstackDetachProcess == 0) {
		goto Exit;
	}
	//m->NtProtectVirtualMemory = NtProtectVirtualMemory;
	//if (m->NtProtectVirtualMemory == 0) {
	//	goto Exit;
	//}

	m->PsTerminateSystemThread = (PVOID)GetProcAddress(L"PsTerminateSystemThread");
	if (m->PsTerminateSystemThread == 0) {
		goto Exit;
	}
	m->ExFreePoolWithTag = (PVOID)GetProcAddress(L"ExFreePoolWithTag");
	if (m->ExFreePoolWithTag == 0) {
		goto Exit;
	}
	m->PsSetCreateProcessNotifyRoutine = (PVOID)GetProcAddress(L"PsSetCreateProcessNotifyRoutine");
	if (m->PsSetCreateProcessNotifyRoutine == 0) {
		goto Exit;
	}
	m->NtAllocateVirtualMemory = (PVOID)GetProcAddress(L"NtAllocateVirtualMemory");
	if (m->NtAllocateVirtualMemory == 0) {
		goto Exit;
	}
	m->KeDelayExecutionThread = (PVOID)GetProcAddress(L"KeDelayExecutionThread");
	if (m->KeDelayExecutionThread == 0) {
		goto Exit;
	}
	m->ZwClose = (PVOID)GetProcAddress(L"ZwClose");
	if (m->ZwClose == 0) {
		goto Exit;
	}
	m->IoAllocateMdl = (PVOID)GetProcAddress(L"IoAllocateMdl");
	if (m->IoAllocateMdl == 0) {
		goto Exit;
	}
	m->MmProbeAndLockPages = (PVOID)GetProcAddress(L"MmProbeAndLockPages");
	if (m->MmProbeAndLockPages == 0) {
		goto Exit;
	}
	m->IoFreeMdl = (PVOID)GetProcAddress(L"IoFreeMdl");
	if (m->IoFreeMdl == 0) {
		goto Exit;
	}
	m->MmBuildMdlForNonPagedPool = (PVOID)GetProcAddress(L"MmBuildMdlForNonPagedPool");
	if (m->MmBuildMdlForNonPagedPool == 0) {
		goto Exit;
	}	
	m->MmMapLockedPagesSpecifyCache = (PVOID)GetProcAddress(L"MmMapLockedPagesSpecifyCache");
	if (m->MmMapLockedPagesSpecifyCache == 0) {
		goto Exit;
	}
	m->MmUnmapLockedPages = (PVOID)GetProcAddress(L"MmUnmapLockedPages");
	if (m->MmUnmapLockedPages == 0) {
		goto Exit;
	}
	m->MmUnlockPages = (PVOID)GetProcAddress(L"MmUnlockPages");
	if (m->MmUnlockPages == 0) {
		goto Exit;
	}
	m->NtFreeVirtualMemory = (PVOID)GetProcAddress(L"NtFreeVirtualMemory");
	if (m->NtFreeVirtualMemory == 0) {
		goto Exit;
	}
	m->MmIsAddressValid = (PVOID)GetProcAddress(L"MmIsAddressValid");
	if (m->MmIsAddressValid == 0) {
		goto Exit;
	}
	m->PsGetProcessSectionBaseAddress = (PVOID)GetProcAddress(L"PsGetProcessSectionBaseAddress");
	if (m->PsGetProcessSectionBaseAddress == 0) {
		goto Exit;
	}
	m->KeWaitForSingleObject = (PVOID)GetProcAddress(L"KeWaitForSingleObject");
	if (m->KeWaitForSingleObject == 0) {
		goto Exit;
	}
	m->DbgPrint = (PVOID)GetProcAddress(L"DbgPrint");
	if (m->DbgPrint == 0) {
		goto Exit;
	}
	m->MmCopyVirtualMemory = (PVOID)GetProcAddress(L"MmCopyVirtualMemory");
	if (m->MmCopyVirtualMemory == 0) {
		goto Exit;
	}
	
	m->KeReleaseSemaphore = (PVOID)GetProcAddress(L"KeReleaseSemaphore");
	if (m->KeReleaseSemaphore == 0) {
		goto Exit;
	}
	m->IoGetCurrentProcess = (PVOID)GetProcAddress(L"IoGetCurrentProcess");
	if (m->IoGetCurrentProcess == 0) {
		goto Exit;
	}
	
	m->PsGetProcessWow64Process = (PVOID)GetProcAddress(L"PsGetProcessWow64Process");
	if (m->PsGetProcessWow64Process == 0) {
		goto Exit;
	}
	
	m->_stricmp = (PVOID)GetProcAddress(L"_stricmp");
	if (m->_stricmp == 0) {
		goto Exit;
	}
	
	m->strlen = (PVOID)GetProcAddress(L"strlen");
	if (m->strlen == 0) {
		goto Exit;
	}
	
	m->RtlAnsiStringToUnicodeString = (PVOID)GetProcAddress(L"RtlAnsiStringToUnicodeString");
	if (m->RtlAnsiStringToUnicodeString == 0) {
		goto Exit;
	}
	m->RtlEqualUnicodeString = (PVOID)GetProcAddress(L"RtlEqualUnicodeString");
	if (m->RtlEqualUnicodeString == 0) {
		goto Exit;
	}
	m->PsGetProcessPeb = (PVOID)GetProcAddress(L"PsGetProcessPeb");
	if (m->PsGetProcessPeb == 0) {
		goto Exit;
	}
	m->KeRaiseIrqlToDpcLevel = (PVOID)GetProcAddress(L"KeRaiseIrqlToDpcLevel");
	if (m->KeRaiseIrqlToDpcLevel == 0) {
		goto Exit;
	}
	
	m->KeLowerIrql = (PVOID)GetProcAddress(L"KeLowerIrql");
	if (m->KeLowerIrql == 0) {
		goto Exit;
	}
	m->KfRaiseIrql = (PVOID)GetProcAddress(L"KfRaiseIrql");
	if (m->KfRaiseIrql == 0) {
		goto Exit;
	}
	m->MmGetPhysicalAddress = (PVOID)GetProcAddress(L"MmGetPhysicalAddress");
	if (m->MmGetPhysicalAddress == 0) {
		goto Exit;
	}
	//if (VisonNum > 6) {

	m->MmCopyMemory = (PVOID)GetProcAddress(L"MmCopyMemory");
	if (m->MmCopyMemory == 0) {
		//OutPut("<-->%d\r\n", 10);
		//goto Exit;
	}
		//OutPut("<-->%d\r\n",10);
	//}
	
	m->IofCompleteRequest = (PVOID)GetProcAddress(L"IofCompleteRequest");
	if (m->IofCompleteRequest == 0) {
		goto Exit;
	}
	//m->IoGetCurrentIrpStackLocation = (PVOID)GetProcAddress(L"IoGetCurrentIrpStackLocation");
	/*m->IoGetCurrentIrpStackLocation = IoGetCurrentIrpStackLocation;
	if (m->IoGetCurrentIrpStackLocation == 0) {
		goto Exit;
	}*/
	
	m->ObOpenObjectByPointer = (PVOID)GetProcAddress(L"ObOpenObjectByPointer");
	if (m->ObOpenObjectByPointer == 0) {
		goto Exit;
	}
	m->NtOpenProcess = (PVOID)GetProcAddress(L"NtOpenProcess");
	if (m->NtOpenProcess == 0) {
		goto Exit;
	}
	m->NtProtectVirtualMemory = NtProtectVirtualMemory;
	if (m->NtProtectVirtualMemory == 0) {
		goto Exit;
	}
	m->NtReadVirtualMemory = NtReadVirtualMemory;
	if (m->NtReadVirtualMemory == 0) {
		goto Exit;
	}
	m->NtWriteVirtualMemory = NtWriteVirtualMemory;
	if (m->NtWriteVirtualMemory == 0) {
		goto Exit;
	}
	
	m->PsGetCurrentThread = (PVOID)GetProcAddress(L"PsGetCurrentThread"); ;
	if (m->PsGetCurrentThread == 0) {
		goto Exit;
	}
	return TRUE;
Exit:
	return FALSE;
}
